/**
 * This class give more specific implementation and construct
 * for missing records
 */

package com.comp6231.replica2.server;

import com.comp6231.replica2.server.helper.IndividualsStatus;

/**
 * @author Farzana Alam
 * 
 */
public class MissingRecord extends Record {

	private String address;
	private String lastLocation;
	private String lastDate;

	/**
	 * @param badgeID
	 * @param recordID
	 * @param lastName
	 * @param firstName
	 * @param address
	 * @param lastDate
	 * @param lastLocation
	 * @param status
	 */
	public MissingRecord(String badgeID, String recordID, String lastName,
			String firstName, String address, String lastDate,
			String lastLocation, IndividualsStatus status) {
		super(badgeID, lastName, firstName, status, recordID);

		this.address = address;
		this.lastDate = lastDate;
		this.lastLocation = lastLocation;
	}

	/**
	 * 
	 * @return
	 */
	public String getAddress() {
		return address;
	}

	/**
	 * 
	 * @param address
	 */
	public void setAddress(String address) {
		this.address = address;
	}

	/**
	 * 
	 * @return
	 */
	public String getLastLocation() {
		return lastLocation;
	}

	/**
	 * 
	 * @param lastLocation
	 */
	public void setLastLocation(String lastLocation) {
		this.lastLocation = lastLocation;
	}

	/**
	 * 
	 * @return
	 */
	public String getLastDate() {
		return lastDate;
	}

	/**
	 * 
	 * @param lastDate
	 */
	public void setLastDate(String lastDate) {
		this.lastDate = lastDate;
	}

	public static Record makeMRObject(String myRecord) {
		/*
		 * the following string format is expected as myRecord
		 * recoredID:lastName
		 * firstName:address:lastDate:lastLocation:status:badgeID
		 */
		String[] temp = myRecord.split(":");

		IndividualsStatus status = null;

		switch (temp[6].toUpperCase()) {
		case "MISSING":
			status = IndividualsStatus.from_int(0);
			break;
		case "FOUND":
			status = IndividualsStatus.from_int(0);
			break;
		case "ON_THE_RUN":
			status = IndividualsStatus.from_int(0);
			break;
		case "CAPTURED":
			status = IndividualsStatus.from_int(0);
			break;

		}
		return new MissingRecord(temp[7], temp[0], temp[1], temp[2], temp[3],
				temp[4], temp[5], status);
	}

	@Override
	public String toString() {
		// recoredID:lastName:firstName:address:lastDate:lastLocation:status:badgeID
		StringBuilder sb = new StringBuilder();
		sb.append(getRecordID()).append("##").append(getLastName())
				.append("##").append(getFirstName()).append("##")
				.append(getAddress());
		sb.append("##").append(getLastDate()).append("##")
				.append(getLastLocation()).append("##");
		sb.append(getStatus().toString()).append("##").append(getBadgeID());

		return sb.toString();
	}
}
